#include "biginteger.h"
int menu(){
     int choice;
     while(choice!=1&&choice!=2&&choice!=3&&choice!=4&&choice!=0){
     system("cls");
     printf("\n******************************************************\n");
     printf("This program will do the calculation of big intenger:");
     printf("\n******************************************************\n");
     printf("\nPlease choose the operator from the menu below:");
     printf("\n1:Addition(+)");
     printf("\n2: Minus(-)");
     printf("\n3: Multiplication(*)");
     printf("\n4: Devide (/)");
     printf("\nInput your choice");
     scanf("%d",&choice);}
     return choice;
}
void input()
{
    char astr[256],bstr[256]; 
    system("cls");     
    printf("Input the a:");
	fflush(stdin);
	gets(astr);
	m=strlen(astr);
	a=(int*)calloc(m,sizeof(int));//finish input calculate the elements of a
    for(i=m-1,j=0;i>-1;i--,j++)
	{
	      a[j]=(astr[i]-'0');
       }//Convert to array
    printf("Input the number b: ");
    fflush(stdin);
    gets(bstr);
   	n=strlen(bstr);
   	b=(int*)calloc(n,sizeof(int));//calculate the elements of b
     for(i=n-1,j=0;i>=0;i--,j++){
          b[j]=bstr[i]-'0';  
          }
    //Buoc 1: Loai bo cac chu so 0 vo nghia o mang a va b
    while((a[m-1]==0)&&(m>0))
        m--;
    if(m==0)
        a[m++]=0;
    while((b[n-1]==0)&&(n>0))
        n--;
    if(n==0)
        b[n++]=0;
}
int main()
{   menu();
    switch(menu()){
    case 1:
    input();
    printf("\nThe Result is:");
    add(a,b);
    break;
    case 2:
    input();
    printf("\nThe Result is:");
    minus(a,b);
    break;
    case 3:
    input();
    printf("\nThe Result is:");
    mul(a,b);
    break;
    case 4:
    d=0;
    i=0;
    t=0;
    check_str();
    if(duoc)
    {
        devide(a,b);
        printf("\nThuong cua phep chia la: ");
        for(j=0;j<t;j++)
        printf("%d",c[j]);
        printf("\nSo du cua phep chia: ");
        for(j=i;j<m;j++)
        printf("%d",a[j]);
    }
    else 
        printf("Chia cho 0!!!! Vui long lam lai....");
}
    getch();
    return 0;
}
